<?php

namespace app\admin\controller;
use app\admin\controller\Main;
use think\Controller;
use think\Db;

class Sysset extends Main {

    public function basic() {
        $_GPC = $this->data;
        if ($this->request->isPost()) {
//            $token = check_formtoken();
//             unset($_GPC['data']['token']);
            $data = Db::name('sysset')->where(array('id' => 1))->find();
                $sets = json_decode($data['sets'], true);
                if ($_GPC['data']['client_key'] == '' && isset($sets['basic'])) {
                    $_GPC['data']['client_key'] = $sets['basic']['client_key'];
                }
                if ($_GPC['data']['client_secret'] == '' && isset($sets['basic'])) {
                    $_GPC['data']['client_secret'] = $sets['basic']['client_secret'];
                }
                if ($_GPC['data']['ali_keyid'] == '' && isset($sets['basic'])) {
                    $_GPC['data']['ali_keyid'] = $sets['basic']['ali_keyid'];
                }
                if ($_GPC['data']['ali_keysecret'] == '' && isset($sets['basic'])) {
                    $_GPC['data']['ali_keysecret'] = $sets['basic']['ali_keysecret'];
                }

                isset($sets['basic']) ? $sets['basic'] = array_merge($sets['basic'], $_GPC['data']) : ($sets['basic'] = $_GPC['data']);
                Db::name('sysset')->where(array('id' => 1))->update(array('sets' => json_encode($sets)));
            return jsonpp([]);
        }
        $result = $this->sysset['basic'];
        return jsonp(get_upload_data($result));
    }
    
    public function adminset() {

        $_GPC = input();
        
        if ($this->request->isPost()) {
            $token = check_formtoken();
             unset($_GPC['data']['token']);
            $data = Db::name('admin')->where(array('username' => "admin"))->find();
            
            if($_GPC['newpw']!=$_GPC['surepw'])
            {
                 jsont([], 1, '两次密码不一致！');
            }
            
            if(md5($_GPC['oldpw'].$data['salt'])==$data['pwd'])
            {
                Db::name('admin')->where(array('username' => "admin"))->update(['pwd'=>md5($_GPC['newpw'].$data['salt'])]);
                return jsonpp([]);
            }

            jsont([], 1, '修改失败！');
        }else{
             return jsonp([]);
        }
       
    }

}
